﻿using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using PineLake.Drmwe.Caching.MemoryCache;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PineLake.Drmwe.Core.Caching
{
    /// <summary>
    /// 内存缓存注入服务
    /// </summary>
    public static class MemoryCacheStartup
    {
        public static void AddMemoryCacheStartup(this IServiceCollection Services)
        {
            if (Services == null) throw new ArgumentNullException(nameof(Services));

            Services.AddScoped<ICaching, MemoryCaching>();
            Services.AddSingleton<IMemoryCache>(Factory =>
            {
                var Cache = new MemoryCache(new MemoryCacheOptions());
                return Cache;
            });
        }
    }
}
